import plotly.express as px
import pandas as pd
import plotly.io as pio

# 设置默认渲染器为浏览器
pio.renderers.default = "browser"

# 创建示例数据
data = {
    "X": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    "Y": [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
    "Z": [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
    "Category": ["A", "A", "A", "B", "B", "B", "C", "C", "C", "C"]
}

# 将数据转换为 DataFrame
df = pd.DataFrame(data)

# 创建三维散点图
fig = px.scatter_3d(
    df,  # 数据
    x="X",  # X 轴数据
    y="Y",  # Y 轴数据
    z="Z",  # Z 轴数据
    color="Category",  # 根据类别着色
    title="三维散点图示例",  # 图表标题
    labels={"X": "X 轴", "Y": "Y 轴", "Z": "Z 轴"}  # 轴标签
)

# 显示图表
fig.show()